/*
 * RSAccessor.h
 *
 *  Created on: 2010/03/16
 *      Author: alexandre
 */

#ifndef RSACCESSOR_H_
#define RSACCESSOR_H_

#include "RSElement.h"

namespace Realsphere {

    class RSAccessor : public Realsphere::RSElement {
        Q_OBJECT
        Q_PROPERTY ( unsigned int _attr_count READ Count )
        Q_PROPERTY ( unsigned int _attr_offset READ Offset WRITE SetOffset )
        Q_PROPERTY ( QString _attr_source READ Source WRITE SetSource )
        Q_PROPERTY ( unsigned int _attr_stride READ Stride WRITE SetStride )
        public:
            Q_INVOKABLE RSAccessor ( Realsphere::RSDataSource* rDataSource, int rOffset = 0, int rStride = 1 );
            virtual ~RSAccessor ();

        public:
            unsigned int            Count () const;
            unsigned int            Offset () const;
            QString                 Source () const;
            unsigned int            Stride () const;

            RSDataSource*           SourceElement () const;

            RSParam*                GetParam ( const QString& rName ) const;
            RSParam*                GetParam ( unsigned int rIndex ) const;
            int                     IndexOf ( RSParam* rParam ) const;
            unsigned int            ParamsSize () const;
            RSParams                Params () const;
            RSParamsIterator        ParamsIterator () const;

            void                    Reset();
            void                    First();
            void                    Next();
            void                    Prev();
            void                    Last();
            bool                    HasNext () const;

            bool                    IsRootElement () const;

        public slots:
            RSError                 SetOffset ( unsigned int rOffset, bool rEmit = true );
            RSError                 SetSource ( const QString& rSourceId, bool rEmit = true );
            RSError                 SetSource ( RSDataSource* rSource, bool rEmit = true);
            RSError                 SetStride ( unsigned int rStride, bool rEmit = true );
            RSError                 AddParam ( RSParam* rParam );
            RSError                 RemoveParam ( RSParam* rParam );
            RSError                 RemoveParam ( unsigned int rIndex );

        signals:
            void                    CountChanged ( unsigned int rCount );
            void                    OffsetChanged ( unsigned int rOffset );
            void                    SourceChanged ( RSDataSource* rSource );
            void                    StrideChanged ( unsigned int rStride );
            void                    ParamAdded ( RSParam* rParam );
            void                    ParamRemoved ( RSParam* rParam );

        protected:
            RSError                 BeforeAddChildElement ( RSElement* rChild );
            bool                    AfterAddChildElement ( RSElement* rChild );
            bool                    AfterRemoveChildElement ( RSElement* rChild );

        private:
            unsigned int            mCount;
            unsigned int            mOffset;
            RSDataSource*           mSource;
            unsigned int            mStride;
            unsigned int            mDataStride;
            RSParams                mParams;
            RSDataPointer           mPosition;
    };

}

#endif /* RSACCESSOR_H_ */
